package com.hanbitexam.action;

import java.util.List;

import com.hanbitexam.dao.CategoryDao;
import com.hanbitexam.vo.CategoryVo;

public class CategoryAction {
	public String catename;
	List<CategoryVo> list;	
	int idx;
	
	public int getIdx() {
		return idx;
	}

	public void setIdx(int idx) {
		this.idx = idx;
	}

	public List<CategoryVo> getList() {
		return list;
	}

	public void setList(List<CategoryVo> list) {
		this.list = list;
	}

	public String getCatename() {
		return catename;
	}

	public void setCatename(String catename) {
		this.catename = catename;
	}

	public String view(){	//카테고리 조회 액션
		
		 		
		try {
			list = CategoryDao.selectAllCategory();
			
			if(catename!=null){
				System.out.println("액션안 : "+catename);
				if(catename.trim().length()>0){
					list=CategoryDao.selectCategory((catename));
				}
			}
			System.out.println("listsize : "+list.size());
		} catch (Exception e) {
			e.printStackTrace();
		}		
		return "success";
	}
	
	public String viewIdx(){
		System.out.println(" +++ CategoryAction's viewIdx() +++ ");
		try{
			list = CategoryDao.selectCategoryByIdx(idx);
						
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return "success";
	}
	
	public String add(){	//카테고리 추가 액션
		
		//CategoryDao cate = new CategoryDao();
		try{			
			CategoryDao.insertCategory(catename);
			
		} catch (Exception e) {
			e.printStackTrace();
			return "fail";
		}		
		return "success";
	}
	
	public String del(){	//카테고리 삭제 액션
		
		System.out.println(" +++ CategoryAction'del()' +++ ");
		System.out.println(" delete category idx : "+idx);
		//CategoryDao cate = new CategoryDao();
		
		try{			
			CategoryDao.deleteCategory(idx);
			
		} catch (Exception e) {
			e.printStackTrace();
			return "fail";
		}		
		return "success";
	}

}
